#include "stdafx.h"
#include "ValidatorSkill.h"
#include "Reactor.h"
#include "Utility.h"


void TSkillValidators::OnArchieveReaded()
{
	m_vValidators.clear();
	if(m_iID==INVALID_ID) return ;
	if(!m_vTypeIn.empty())
	{
		VSkill_TypeCheck* pV=new VSkill_TypeCheck();
		pV->InitData(m_vTypeIn);
		pV->SetInclude(true);
		Add(TValidatorSkillPtr(pV));
	}
	if(!m_vTypeNotIn.empty())
	{
		VSkill_TypeCheck* pV=new VSkill_TypeCheck();
		pV->InitData(m_vTypeNotIn);
		pV->SetInclude(false);
		Add(TValidatorSkillPtr(pV));
	}
	if(!m_vCategoryMustInclude.empty())
	{
		VSkill_CategoryCheck* pV=new VSkill_CategoryCheck();
		pV->InitData(m_vCategoryMustInclude);
		pV->SetInclude(true);
		Add(TValidatorSkillPtr(pV));
	}
	if(!m_vCategoryMustNotInclude.empty())
	{
		VSkill_CategoryCheck* pV=new VSkill_CategoryCheck();
		pV->InitData(m_vCategoryMustNotInclude);
		pV->SetInclude(false);
		Add(TValidatorSkillPtr(pV));
	}
}

bool VSkill_TypeCheck::Validate(const Reactor * pRecator) const
{
	return Util::RangeCheckID(m_bIncludeOrExclude,pRecator->GetType(),m_vTypes);
}

bool VSkill_CategoryCheck::Validate(const Reactor * pRecator) const
{
	const std::vector<int32>&  rCategorys=pRecator->GetCategorys();
	if(m_bIncludeOrExclude)
	{
		for(uint32 ii=0;ii<m_vCategorys.size();ii++)
		{
			if(!Util::RangeCheckID(true,m_vCategorys[ii],rCategorys)) return false;
		}
		return true;
	}
	else
	{
		for(uint32 ii=0;ii<m_vCategorys.size();ii++)
		{
			if(Util::RangeCheckID(true,m_vCategorys[ii],rCategorys)) return false;
		}	
		return true;
	}
	
}
